package org.erik.jdk8.study.steam;

import sun.rmi.transport.StreamRemoteCall;

import java.util.ArrayList;
import java.util.List;
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;

/**
 * @author Erik
 * @create 2020-05-19 10:17
 * @description
 **/
public class StuTest {

    public  static List<Student> getStudents(){
        List<Student> list = new ArrayList<>();
        list.add(new Student(1,"刘备",18,90.4));
        list.add(new Student(2,"张飞",19,87.4));
        list.add(new Student(3,"关羽",21,67.4));
        list.add(new Student(4,"赵云",15,89.4));
        list.add(new Student(5,"马超",16,91.4));
        list.add(new Student(6,"曹操",19,83.4));
        list.add(new Student(7,"荀彧",24,78.4));
        list.add(new Student(8,"孙权",26,79.4));
        list.add(new Student(9,"鲁肃",21,93.4));
        return list;
    }

    public static void main(String[] args) {
        List<Student> list = getStudents();

        DoubleStream scoreList = list.stream().mapToDouble(s -> s.getScore());
        OptionalDouble total = scoreList.reduce(Double::sum);
        System.out.println(total.toString());

    }


}
